Namespace Validaciones
    Public Class ValidacionImei
        Public Shared Function ValidarImei(ByVal strImei As String) As Boolean
            Dim blnValido As Boolean = False
            Dim arrayNumeros As New ArrayList
            Dim i As Integer
            Dim conteo As Integer = 0
            Dim suma As Integer = 0
            Try
                If strImei.Length > 0 Then
                    For i = 0 To strImei.Length - 1
                        If IsNumeric(strImei(i)) Then
                            arrayNumeros.Add(CInt(strImei(i).ToString))
                            If conteo < 14 Then
                                If (conteo > 0) And (conteo Mod 2 <> 0) Then
                                    arrayNumeros.Item(conteo) = arrayNumeros.Item(conteo) * 2
                                    If arrayNumeros.Item(conteo) > 9 Then
                                        Dim strDig As String = arrayNumeros.Item(conteo).ToString
                                        arrayNumeros.Item(conteo) = CInt(strDig(0).ToString) + CInt(strDig(1).ToString)
                                    End If
                                End If
                                suma += arrayNumeros.Item(conteo)
                                conteo += 1
                            End If
                        End If
                    Next

                    If conteo = 14 Then
                        Dim valorSumas As Integer
                        Dim strSuma As String = suma.ToString
                        Dim validador As Integer = arrayNumeros.Item(14)


                        If suma >= 10 Then
                            If CInt(strSuma(1).ToString) > 0 Then
                                valorSumas = 10 - CInt(strSuma(1).ToString)
                            ElseIf CInt(strSuma(1).ToString) = 0 Then
                                valorSumas = 0
                            End If

                            If valorSumas = validador Then
                                blnValido = True
                            Else
                                blnValido = False
                            End If
                        Else 'If suma > 0 And suma > 10 Then
                            If suma = validador Then
                                blnValido = True
                            Else
                                blnValido = False
                            End If
                        End If
                    Else
                        blnValido = False
                    End If
                End If
            Catch ex As Exception
                blnValido = False
            End Try
            Return blnValido


        End Function
    End Class
End Namespace
